package com.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.core.pojo.OrderDo;
import com.core.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author SunChangSheng
 * @apiNote
 * @since 2021/8/18 18:49
 */
@Log4j2
@RestController
@RequestMapping("order")
public class OrderController {
    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 添加订单
     * @return
     */
    @RequestMapping("add")
    @Transactional(rollbackFor = Exception.class)
    public boolean add() {
        System.out.println("添加订单");
        OrderDo orderDo = new OrderDo();
        orderDo.setStockId(1);
        orderDo.setUname("努力的蚂蚁");
        orderDo.setCreateTime(new Date());
        orderService.save(orderDo);
        int a=10/0;
        return true;
    }

    public static void main(String[] args) {
        List<Integer> list=new ArrayList(5);
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        System.out.println(list.size());

    }
}
